package com.SmartCare.controller.manager;


import com.SmartCare.common.Result;
import com.SmartCare.service.medicine.MedicationRecordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 前端控制器
 */
@RestController
@RequestMapping("/medication-record")
public class MedicationRecordController {
    @Resource
    private MedicationRecordService medicationRecordService;

    //生成当天用药记录
    @GetMapping("/generate")
    public Result generateTodayRecords() {
        return medicationRecordService.generateTodayRecords();
    }

    //获取指定养老院的用药记录列表分页数据
    @GetMapping("/query")
    public Result getMedicationRecords(@RequestParam Integer pageNum,
                                       @RequestParam Integer pageSize,
                                       @RequestParam String keyword,
                                       @RequestParam String type,
                                       @RequestParam String name) {
        return medicationRecordService.getPageRecords(name, pageSize, pageNum, keyword, type);
    }
    //获取相关信息
    @GetMapping("/query-data")
    public Result getMedicationRecordsData(@RequestParam String name){
        return medicationRecordService.getRecordsData(name);
    }

    //更新状态
    @PutMapping("/update-status")
    public Result updateRecordsStatus(@RequestParam Long id, @RequestParam Integer status){
        return medicationRecordService.updateStatus(id, status);
    }

    //导出记录
    @GetMapping("/export/{name}/{id}")
    public void export(HttpServletResponse response, @PathVariable String name, @PathVariable Long id) {
        medicationRecordService.export(response, name, id);
    }
}

